<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<meta name="author" content="order by dede58.com" />
	<title>用户注册</title>
	<link rel="stylesheet" href="/static/itying/css/login.css" />
	<script src="/static/itying/js/jquery-1.10.1.js"></script>
</head>

<body class="register_page">
	<div class="regist">
		<div class="regist_center">
			<div class="logo">
				<img src="/static/itying/image/logo_top.png" alt="nest小米">
			</div>
			<div class="regist_top">
				<h2>注册小米账户</h2>
			</div>
			<div class="regist_main center">
				<p>验证码已通过短信发送至{{.phone}}，请输入完成验证。手机绑定是为保障用户的信息真实性和帐号安全性</p>
				<br>
				<br>
				<div class="error"></div>
				<input type="hidden" id="phone" name="phone" value="{{.phone}}" />
				<input type="hidden" id="photo_code" name="photo_code" value="{{.photo_code}}" />
				<input type="hidden" id="sign" name="sign" value="{{.sign}}" />

				<div class="yzm">
					<input type="text" id="sms_code" name="sms_code" placeholder="请输入验证码" />
					<button id="sendCode">重新发送</button>
				</div>

				<div class="regist_submit">
					<input class="submit" id="nextStep" type="button" name="submit" value="下一步">
					<br>
					<input class="return" id="returnButton" type="button" name="return" value="返回">
				</div>
			</div>

			<script>

				$(function () {

					var timer = 10;
					function Countdown() {
						if (timer >= 1) {
							timer -= 1;
							$("#sendCode").attr('disabled', true);
							$("#sendCode").html('重新发送(' + timer + ')');
							setTimeout(function () {
								Countdown();
							}, 1000);
						} else {
							$("#sendCode").attr('disabled', false)

							$("#sendCode").html('重新发送');
						}
					}
					//发送验证码
					Countdown();


					$("#sendCode").click(function () {
						$(".error").html("")
						timer=10
						Countdown();
						var phone = $("#phone").val()
						var photo_code = $("#photo_code").val()
						var photoCodeId = "resend"
						// alert('重新发送');
						$.get('/pass/sendCode', { phone: phone, photo_code: photo_code, photoCodeId: photoCodeId }, function (response) {
							console.log(response)
							if (response.success != true) {
								//改变验证码											
								$(".error").html("Error：" + response.msg + ",请重新输入!")
							} 
						})
					})

				})

				//验证验证码		
				$(function () {

					$("#nextStep").click(function (e) {

						var sign = $('#sign').val();
						var sms_code = $('#sms_code').val();

						$.get('/pass/validateSmsCode', { sign: sign, sms_code: sms_code }, function (response) {
							if (response.success == true) {
								location.href = "/pass/registerStep3?sign=" + sign + "&sms_code=" + sms_code
							} else {
								
								$(".error").html("Error：" + response.msg)
							}
						})

					})

				})

			</script>

		</div>
	</div>

</body>

</html>